package com.xhwl.data.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xhwl.common.dto.cent.sdata.*;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.*;
import com.xhwl.common.query.cent.sdata.PermissionQuery;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author:
 * @create: 2020-11-25
 **/

@RestController
public interface IPermissionService extends IService<Permission> {

    /**
     * 获取权限树
     *
     * @param permissionTreeDTO
     * @param account
     * @return
     */
    @RequestMapping(value = "/permission-service/get-permission-tree", method = RequestMethod.POST)
    List<AppPermissionMenuDTO> getPermissionTree(@RequestPart(value = "permissionTreeDTO", required = false) PermissionTreeDTO permissionTreeDTO, @RequestPart("account") Account account);

    /**
     * 根据项目id获取 权限list
     * @param excludeIds
     * @param projectId
     * @return
     */
    @RequestMapping(value = "/permission-service/list-by-proId", method = RequestMethod.POST)
    List<Permission> getListByProjectId(@RequestPart("excludeIds") List<Integer> excludeIds, @RequestPart("projectId") Integer projectId);


    /**
     * 根据角色id获取 权限list
     *
     * @param roleId
     * @return
     */
    @RequestMapping(value = "/permission-service/list-by-roleId", method = RequestMethod.POST)
    List<Permission> getListByRoleId(@RequestPart(value = "appId", required = false) String appId,@RequestPart("roleId") Integer roleId);

    /**
     * 根据企业id获取 权限list
     *
     * @param excludeIds
     * @param enterpriseId
     * @return
     */
    @RequestMapping(value = "/permission-service/list-by-entId", method = RequestMethod.POST)
    List<Permission> getListByEnterpriseId(@RequestPart("excludeIds") List<Integer> excludeIds, @RequestPart("enterpriseId") Integer enterpriseId);


    /**
     * 根据业态id获取 权限树
     * @param industryId
     * @return
     */
    @RequestMapping(value = "/permission-service/tree-by-industryId", method = RequestMethod.POST)
    List<AppPermissionMenuDTO> getTreeListByIndustryId(@RequestPart("industryId")Short industryId);


    /**
     * 获取账号的权限菜单列表树
     *
     * @param account
     * @param projectId
     * @param appId
     * @return
     */
    @RequestMapping(value = "/permission-service/menu-by-account", method = RequestMethod.POST)
    List<PermissionDTO> getPermissionTreeByAccount(@RequestPart("account") Account account, @RequestPart(value = "projectId", required = false) Integer projectId, @RequestPart(value = "appId", required = false) String appId);

    /**
     * 同上 getPermissionTreeByAccount 方法
     * 不同： 企业管理员会根据传入的企业id查询传入企业的权限，例如运营商管理员选择服务商企业的时候
     * @param account
     * @param permissionQuery
     * @param appId
     * @return
     */
    List<PermissionDTO> getPermissionTreeByAccount(Account account, PermissionQuery permissionQuery, String appId);

    /**
     * 获取默认菜单树
     *
     * @param appId
     * @return
     */
    @RequestMapping(value = "/permission-service/default-menu-tree", method = RequestMethod.POST)
    List<PermissionDTO> getDefaultPermissionTree(@RequestPart(value = "appId", required = false) String appId, @RequestPart(value = "needAll", required = false) Boolean needAll);

    /**
     * 获取默认菜单code
     *
     * @param appId
     * @return
     */
    @RequestMapping(value = "/permission-service/default-codes", method = RequestMethod.POST)
    List<Permission> getDefaultPermissions(@RequestPart(value = "appId", required = false) String appId, @RequestPart(value = "needAll", required = false) Boolean needAll);


    /**
     * 获取某个父级菜单 下的所有 子菜单（包括按钮）
     * @param id
     * @param allPermission
     * @param resultPermission
     * @return
     */
     List<PermissionDTO> getChild(Integer id, List<Permission> allPermission,List<Permission> resultPermission);


    /**
     * 创建权限
     *
     * @param appPermissionDTO
     * @return
     */

    @RequestMapping(value = "/permission-service/create-permission", method = RequestMethod.POST)
    ResultJson createPermission(@RequestPart("appPermissionDTO") AppPermissionDTO appPermissionDTO);

    /**
     * 删除权限码 真删除
     *
     * @param permissionIdList
     * @return
     */
    @RequestMapping(value = "/permission-service/delete-permission", method = RequestMethod.POST)
    ResultJson deletePermission(@RequestPart("permissionIdList") List<Integer> permissionIdList);


    /**
     * 修改权限 /包括关联的APP表
     *
     * @param appPermissionDTO
     * @return
     */
    @RequestMapping(value = "/permission-service/update-permission", method = RequestMethod.POST)
    ResultJson updatePermission(@RequestPart("appPermissionDTO") AppPermissionDTO appPermissionDTO);


    /**
     * 动态获取 权限码list
     *
     * @param page
     * @param permissionQuery
     * @return
     */
    @RequestMapping(value = "/permission-service/get-permissionPageList", method = RequestMethod.POST)
    Page<Permission> getPermissionPageList(@RequestPart("page") Page page, @RequestPart(name = "permissionQuery", required = false) PermissionQuery permissionQuery);


    /**
     * 权限码list
     *
     * @param permissionQuery
     * @return
     */
    @RequestMapping(value = "/permission-service/get-permissionList", method = RequestMethod.POST)
    List<Permission> getPermissionList(@RequestPart("permissionQuery") PermissionQuery permissionQuery);


    /**
     * 将权限树根据appId分组
     *
     * @param permissionTotalList
     * @return
     */
    List<AppPermissionMenuDTO> getPermissionTreeGroupByApp(List<PermissionDTO> permissionTotalList);


    /**
     * 根据菜单查询下层按钮
     *
     * @param permissionIdList
     * @return
     */
    List<Integer> findButtonIdByMenuId(List<Integer> permissionIdList);

    /**
     * 账号的企业权限
     * @param account
     * @return
     */
    List<Permission> getEnPermissionByAccount(Account account);

    List<Permission> getProPermissionByAccount(Account account);

    List<Permission> getRolePermissionByAccount(Integer projectId, Account account, App app);

	@RequestMapping(value = "/permission-service/batch-create", method = RequestMethod.POST)
    ResultJson adminBatchCreate(@RequestPart("permissions")List<Permission> permission);

	Integer autoIncr();

    /**
     * 根据运管帐号获取后台的权限树
     * @param adminAccount
     * @return
     */
	List<PermissionDTO> getAdminAccountPermissionTree(AdminAccount adminAccount, App app);

    /**
     * 运管平台获取权限树 (已移除项目范围权限)
     * @param permissionTreeDTO
     * @return
     */
    List<AppPermissionMenuDTO> getPermissionTreeAdmin(PermissionTreeDTO permissionTreeDTO);

    /**
     * 通过权限组获取权限
     * @param permissionQuery
     * @return
     */
    List<PermissionDTO> getPermissionFromGroup(PermissionQuery permissionQuery);

    /**
     * 获取权限树
     * @param permissionTreeDTO
     * @return
     */
    List<AppPermissionMenuDTO> getPermissionTree(PermissionTreeDTO permissionTreeDTO);

    /**
     * 根据菜单ID集合查询所有父级
     * @param permissionIds
     * @return
     */
    @RequestMapping(value = "/permission-service/get-parent-permissionList")
    List<Permission> getParent(@RequestPart("permissionIds") List<Integer> permissionIds);

    List<PermissionDTO> getPermissionTreeByRole(Role role);

    List<ScenePermissionMenuDTO> permissionTreeAdmin(PermissionTreeDTO permissionTreeDTO);
}
